<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/11/30
 * Time: 11:32
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\model\mysql;

use app\common\lib\Status;

class Collection extends Base
{
    /**
     * @param int $theatre_id
     * @param string $openid
     * @param string $field
     * @return Collection|array|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getCollectionByOpenid(int $theatre_id = 0, string $openid = "", string $field = "*")
    {
        return $this->field($field)
            ->where('openid', $openid)
            ->where('theatre_id', $theatre_id)
            ->where('status', Status::mysql_normal)
            ->find();
    }

    /**
     * @param string $openid
     * @param string $field
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getCollectionByList(string $openid = '', string $field = '*')
    {
        return $this->field($field)
            ->where('openid', $openid)
            ->where('status', 1)
            ->order('id desc')
            ->select()
            ->toArray();
    }

    public function getGetTheatreDataAttr($value)
    {
        $theatre = (new Theatre())->getBaseById((int)$value, '*,thumb as root_path_thumb,start_time as start_day,start_time as start_day_time,end_time as end_day_time,start_time as start_date_a,start_time as big_time');
        if (!$theatre) {
            return [];
        }
        return $theatre->toArray();
    }

    protected function getBigTimeAttr($value)
    {
        return time();
    }
}